﻿using System.Data;

namespace DataAccess
{
    /// <summary>
    /// Database agnostic parameter information.
    /// It can be added to the array of parameters without requiring knowledge of the database type.
    /// At the moment of execution, the database specific parameter will be created
    /// </summary>
    public class DatabaseParameter
    {
        public DatabaseParameter()
        {
            _Direction = ParameterDirection.Input;
        }

        #region Properties

        /// <summary>
        /// The name of the parameter
        /// </summary>
        internal string _Name { get; set; }

        /// <summary>
        /// The value of the parameter
        /// </summary>
        internal object _Value { get; set; }

        /// <summary>
        /// The size of the data type for IN OUT parameters of type string
        /// </summary>
        internal int? _Size { get; set; }

        /// <summary>
        /// The sql type of the parameter
        /// </summary>
        internal int? _Type { get; set; }

        /// <summary>
        /// The direction of the parameter
        /// </summary>
        internal ParameterDirection _Direction { get; set; }

        #endregion

        public override string ToString()
        {
            return string.Format("Name: '{0}', Value: '{1}', Direction: '{2}'", _Name, _Value, _Direction);
        }

        #region Fluent

        public DatabaseParameter IsInput()
        {
            _Direction = ParameterDirection.Input;
            return this;
        }

        public DatabaseParameter IsOutput()
        {
            _Direction = ParameterDirection.Output;
            return this;
        }

        public DatabaseParameter IsInputOutput()
        {
            _Direction = ParameterDirection.InputOutput;
            return this;
        }

        public DatabaseParameter IsReturnValue()
        {
            _Direction = ParameterDirection.ReturnValue;
            return this;
        }

        public DatabaseParameter Value(object value)
        {
            _Value = value;
            return this;
        }

        public DatabaseParameter Size(int size)
        {
            _Size = size;
            return this;
        }

        #endregion
    }
}
